<?php

namespace app\admin\model;

use app\admin\library\Auth;
use app\common\model\BaseModel;

class AuthGroupAccess extends BaseModel
{

    public function setAccess($uid,$group)
    {
        if (!$group) return ;
        $childrenGroupIds = Auth::instance()->getChildrenGroupIds(true);
        $group = array_intersect($childrenGroupIds, $group);
        $dataset = [];
        foreach ($group as $value) {
            $dataset[] = ['uid' => $uid, 'group_id' => $value];
        }
        // 先移除所有权限
        $this->where('uid', $uid)->save(['delete_time'=>time()]);
        $this->saveAll($dataset);

    }

}
